import React, { FC, useCallback } from 'react';
import { View, Text } from '@tarojs/components';
import { styled } from 'linaria/react';
import { useClassName } from '@/utils/index';
import Item from './Item/Item';
import Taro from '@tarojs/taro';
import { listArrType } from '../useMine';
export interface IProps extends ICompProps {
    listArr: listArrType;
}
List.defaultProps = {
    listArr: [],
} as Partial<IProps>;
const cssBorder = '2px solid #F3F3F3';
function List(props: IProps) {
    const { className, style, listArr } = props;
    const localClassName = useClassName('List', className);
    const click = useCallback((url: string) => {
        var value = Taro.getStorageSync('token');
        if (!value)
            return Taro.navigateTo({
                url: 'pages/Login/Login',
            });
        if (url === 'pages/Login/Login')
            Taro.showToast({
                title: '记得调退出接口',
                icon: 'none',
                duration: 10000,
            });
        Taro.navigateTo({
            url: url,
        });
    }, []);
    return (
        <RootView className={localClassName} style={style}>
            <View>
                {listArr.map((item, index) => {
                    return (
                        <View onClick={() => click(item.url)} key={index}>
                            <Item
                                iconCode={item.iconCode}
                                title={item.title}
                                style={{
                                    borderBottom: index == listArr.length - 1 ? 0 : cssBorder,
                                    marginBottom: index == listArr.length - 1 && 0,
                                }}></Item>
                        </View>
                    );
                })}
            </View>
        </RootView>
    );
}
export default React.memo(List as FC<IProps>);

const RootView = styled(View)`
    &.List {
        padding-left: 10px;
    }
`;
